<?php require_once('../Connections/locale.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE lettere_predefinite SET titolo=%s, testo=%s WHERE id_lettera=%s",
                       GetSQLValueString($_POST['titolo'], "text"),
                       GetSQLValueString($_POST['testo'], "text"),
                       GetSQLValueString($_POST['id_lettera'], "int"));

  mysql_select_db($database_locale, $locale);
  $Result1 = mysql_query($updateSQL, $locale) or die(mysql_error());

  $updateGoTo = "elenco_lettere_predefinite.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_lettera = "-1";
if (isset($_GET['id_lettera'])) {
  $colname_lettera = (get_magic_quotes_gpc()) ? $_GET['id_lettera'] : addslashes($_GET['id_lettera']);
}
mysql_select_db($database_locale, $locale);
$query_lettera = sprintf("SELECT * FROM lettere_predefinite WHERE id_lettera = %s", $colname_lettera);
$lettera = mysql_query($query_lettera, $locale) or die(mysql_error());
$row_lettera = mysql_fetch_assoc($lettera);
$totalRows_lettera = mysql_num_rows($lettera);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript" src="../jscripts/tiny_mce/tiny_mce.js"></script>
<link href="../style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<script language="javascript" type="text/javascript">
tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink",
	theme_advanced_buttons2 : "",
	theme_advanced_buttons3 : "",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_path_location : "bottom",
	extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]"
});
</script>
<fieldset>
<legend>Nuovo Template Lettera</legend>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  <table align="left">
    <tr valign="baseline">
      <td nowrap align="right">ID:</td>
      <td><?php echo $row_lettera['id_lettera']; ?></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Titolo:</td>
      <td><input type="text" name="titolo" value="<?php echo $row_lettera['titolo']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Testo:</td>
      <td><textarea name="testo" cols="80" rows="20"><?php echo $row_lettera['testo']; ?></textarea></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Update record"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1">
  <input type="hidden" name="id_lettera" value="<?php echo $row_lettera['id_lettera']; ?>">
</form>
</fieldset>

<br>
<fieldset>
<legend>TAGS</legend>
<p><strong>#NOMINATIVO#</strong> <em>Nominativo Cliente</em> <br>
  <strong>#RIVISTA#</strong> <em>Nome Rivista</em><br>
  <strong>#SCADENZA#</strong> <em>Data Scadenza </em></p>
</fieldset>
<p><a href="elenco_lettere_predefinite.php">&lt;- Torna a Elenco Lettere</a> </p></body>
</body>
</html>
<?php
mysql_free_result($lettera);
?>
